package com.hutra.security {
	
	public class XORCipher {
		private static function xor(source:String, key:String):String {
			var result:String = new String();
			for (var i:Number = 0; i < source.length; i++) {
				if (i > (key.length - 1)) {
					key += key;
				}
				result += String.fromCharCode(source.charCodeAt(i) ^ key.charCodeAt(i));
			}
			return result;
		}
		
		public static function Encode(source:String, key:String):String {
			return Base64.encode(XORCipher.xor(source, key));
		}
		
		public static function Decode(source:String, key:String):String {
			return XORCipher.xor(Base64.decode(source).toString(), key);
		}
	
	}

}